package example.guice.web.provider

import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.datatype.joda.JodaModule
import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider

import grizzled.slf4j.Logging
import javax.ws.rs.Consumes
import javax.ws.rs.Produces
import javax.ws.rs.ext.Provider
import javax.ws.rs.core.MediaType._

object ExampleJacksonJaxbJsonProvider {
  
  def getObjectMapper() = {
    val objectMapper = new ObjectMapper()
    objectMapper.registerModule(new JodaModule());
    objectMapper
  }
  
}

@Provider
@Consumes(Array(WILDCARD)) // NOTE: required to support "non-standard" JSON variants
@Produces(Array(WILDCARD))
class ExampleJacksonJaxbJsonProvider extends JacksonJaxbJsonProvider with Logging {
  setMapper(ExampleJacksonJaxbJsonProvider.getObjectMapper);

  configure(com.fasterxml.jackson.databind.SerializationFeature.
        WRITE_DATES_AS_TIMESTAMPS , false);
  
}